package com.sanpu.kxe.business.card.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.card.bean.BankInfoOutput;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.module.roundview.RoundLinearLayout;
import com.sanpu.kxe.module.roundview.RoundTextView;

import java.util.ArrayList;

/**
 * Description：信用卡列表
 * Created by 薛勇军 on 2019/5/28.
 */

public class CreditCardAdapter extends BaseQuickAdapter<BankInfoOutput, BaseViewHolder> {

    public CreditCardAdapter() {
        super(R.layout.item_credit_card, new ArrayList<BankInfoOutput>());
    }

    @Override
    protected void convert(BaseViewHolder helper, BankInfoOutput item) {
        RoundLinearLayout itemView = helper.getView(R.id.item_view);   //item项
        RoundLinearLayout headView = helper.getView(R.id.head_view);
        ImageView bankIcon = helper.getView(R.id.bankIcon);   //银行icon
        TextView cardNameTv = helper.getView(R.id.cardNameTv); //银行名称
        TextView bankNoTv = helper.getView(R.id.bankNoTv); //银行卡号
        LinearLayout overdueLl = helper.getView(R.id.overdueLl);
        TextView overdueTv = helper.getView(R.id.overdueTv);
        LinearLayout repayRl = helper.getView(R.id.repayRl);
        TextView billDayTv = helper.getView(R.id.billDayTv);  //账单日
        TextView refundDayTv = helper.getView(R.id.refundDayTv);//还款日
        RoundTextView updateTv = helper.getView(R.id.updateTv);
        RoundTextView queryTv = helper.getView(R.id.queryTv);
        RoundTextView refundTv = helper.getView(R.id.refundTv);
        helper.addOnClickListener(R.id.updateTv)
                .addOnClickListener(R.id.queryTv)
                .addOnClickListener(R.id.refundTv);

        if (item != null) {
            try {
                cardNameTv.setText(item.getBankName());
                String bankNo = item.getBankNo();
                bankNoTv.setText("(" + bankNo.substring(bankNo.length() - 4) + ")");
                JKImageLoader.getInstance().displayImage(mContext,
                        UrlConstants.getBaseUrl() + item.getLogoPath(), bankIcon);

//                int[] colors = {Color.parseColor("#"+item.getCardColorStart()), Color.parseColor("#"+item.getCardColorEnd())};
//                GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
//                drawable.setCornerRadius(ScreenUtil.dp2px(3));
//                drawable.setShape(GradientDrawable.RECTANGLE);
//                drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
                itemView.getDelegate().setStrokeColor(Color.parseColor("#"+item.getCardColorStart()));
                headView.getDelegate().setBackgroundColor(Color.parseColor("#"+item.getCardColorStart()));
                updateTv.getDelegate().setBackgroundColor(Color.parseColor("#"+item.getCardColorStart()));
                queryTv.getDelegate().setBackgroundColor(Color.parseColor("#"+item.getCardColorStart()));
                refundTv.getDelegate().setBackgroundColor(Color.parseColor("#"+item.getCardColorStart()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!TextUtils.isEmpty(item.getOverdueDays())) {
                overdueLl.setVisibility(View.VISIBLE);
                overdueTv.setText(item.getOverdueDays());
            } else {
                overdueLl.setVisibility(View.GONE);
            }
            if (!TextUtils.isEmpty(item.getBillDay())) {
                repayRl.setVisibility(View.VISIBLE);
                billDayTv.setText("账单日：每月" + item.getBillDay() + "号");
            } else {
                repayRl.setVisibility(View.GONE);
                billDayTv.setText("账单日：");
            }
            if (!TextUtils.isEmpty(item.getDueDay())) {
                refundDayTv.setText("还款日：每月" + item.getDueDay() + "号");
            } else {
                refundDayTv.setText("还款日：");
            }
        }
    }
}
